import React, { Component } from 'react';
import { Tabs } from 'antd';
import DpTable from './DianPuTable'
import axios from 'axios'
import './rz.css'

class Dianpurenz extends Component {
  constructor() {
    super()
    this.state = {
      fulist: [],
      list: []
    }
  }
  //发起请求获取表格数据
  getTableValue(jiekou, type) {
    if (type === 'get') {
      axios.get(jiekou).then((res) => {
        if (res.data.code === 0) {
          res.data.data.list.forEach((item, index) => {
            item.shopStatus = item.shopStatus === 0 ?
              '待审核' : item.shopStatus === 1 ?
                '已认证' : '已驳回'
            item['key'] = index + 1
          })
          this.setState({
            fulist: [...res.data.data.list]
          }, () => {
            // console.log(this.state.fulist);
          })
        } else {
        }
      })
    } else {
      axios.post(jiekou).then((res) => {
        if (res.data.code === 0) {
          res.data.data.list.forEach((item, index) => {
            item.shopStatus = item.shopStatus === 0 ?
              '待审核' : item.shopStatus === 1 ?
                '已认证' : '已驳回'
            item['key'] = index + 1
          })
          this.setState({
            fulist: [...res.data.data.list]
          }, () => {
            // console.log(this.state.fulist);
          })

        } else {

        }
      })
    }

  }
  // tab栏切换
  callback = (key) => {
    if (key === '1') {
      this.getTableValue('/api/admin/shopView/page', 'get')
    } else if (key === '2') {
      this.getTableValue('/api/admin/attestation/pending', 'post')
    } else if (key === '3') {
      this.getTableValue('/api/admin/attestation/rejected', 'post')
    }

  }
  render() {
    const { TabPane } = Tabs;
    return (
      <div className='content'>
        <div className='nr'>
          <Tabs defaultActiveKey="1" onChange={this.callback}>
            <TabPane tab="全部" key="1">

            </TabPane>
            <TabPane tab="待审核" key="2" >

            </TabPane>
            <TabPane tab="已驳回" key="3">
            </TabPane>
          </Tabs>
          <DpTable getList={this.state.fulist} history={this.props.history} />
        </div>
      </div>
    );
  }
}

export default Dianpurenz;